<template>
  <div class="block-box" :style="style">
    <span class="content">{{ value }}</span>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, type CSSProperties } from 'vue';
import { TYPE_COLOR } from './constants';

type TProps = {
  color: string,
  type: string,
  value: string | number,
  styles: any
}

// 接收属性并定义默认值
const props = withDefaults(defineProps<TProps>(), {
  color: '#67C23A',
  type: 'default',
  value: 0,
  styles: {}
})

const style = ref<any>({ backgroundColor: props.color })

onMounted(() => {
  const styles: any = {}
  styles.backgroundColor = TYPE_COLOR[props.type] || props.color
  Object.keys(props.styles).forEach(key => {
    const val: string = !isNaN(props.styles[key]) ? props.styles[key] + 'px' : props.styles[key]
    styles[key] = val
  })
  style.value = styles
})

</script>

<style lang="less" scoped>
.block-box {
  display: flex;
  justify-content: center;
  align-items: center;
  width: fit-content;
  height: fit-content;
  padding: 0 6px;
  margin-top: 2px;
  border-radius: 10px;
  .content {
    color: #fff;
    font-size: 10px;
  }
}
</style>
